package projectxxx;

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;
import java.util.*;
import com.toedter.calendar.*;
import java.sql.*;

public class MainSouthStockPanel extends JPanel implements ActionListener
{
	private JPanel southP=null;
	private JButton editB=null, delB=null, returnB=null;
	MainWestStockPanel mwsp=null;
	private String myDriver = "com.mysql.jdbc.Driver";
	private	String ipOfDB = "localhost";
	private	MySQLdriverConnection msc=null;
	private	Connection Conn=null;
	private Vector StockTypeNameV=null;
	
	public MainSouthStockPanel() 
	{
		mwsp = new MainWestStockPanel();
		southP = new JPanel(); 
		BoxLayout b4 = new BoxLayout(southP, BoxLayout.X_AXIS);
		southP.setLayout(b4);
		editB = new JButton(" Edit ");
		editB.setToolTipText(" Edit stock item ");
		editB.addActionListener(this);
		delB = new JButton(" Delete ");
		delB.setToolTipText(" Delete stock item ");	
		delB.addActionListener(this);
		returnB = new JButton(" Return "); 
		returnB.setToolTipText(" Return to main page ");
		
		southP.add(editB);
		southP.add(delB);
		southP.add(returnB);	
		southP.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
		
		//setup "this" Jpanel
		this.setLayout(new GridLayout(1,1));
		this.add(southP);
	}
	
		public void actionPerformed(ActionEvent ae)
	{
		Object source = ae.getSource();
		if(source == editB)
		{
			try
			{
				msc = new MySQLdriverConnection("","",ipOfDB,"turtledata");
				Conn = msc.getConnection();
			}
			catch(SQLException sqlE)
			{
				sqlE.printStackTrace();
			}	
			catch(ClassNotFoundException cnfe)
			{
				cnfe.printStackTrace();
			}
			
			try
			{
				
				Statement getStockTypeNameStmt = Conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
				ResultSet StockTypeNameRS;
				String stockTypeTableQuery = "SELECT stockTypeName FROM stockTypeTable WHERE stockTypeId = ' '";
				StockTypeNameRS = getStockTypeNameStmt.executeQuery(stockTypeTableQuery);
				String tempSTR;
				StockTypeNameRS.last();
				int rows = StockTypeNameRS.getRow();
				StockTypeNameRS.first();
				StockTypeNameV = new Vector();
				for(int i = 1;i <= rows;i++ )
				{
					tempSTR = StockTypeNameRS.getString(1);
					
					System.out.println(""+tempSTR);
					StockTypeNameV.addElement(tempSTR);
					
					StockTypeNameRS.next();
				}
			}
			catch(SQLException sqlE)
			{
				System.out.println("No problemo");
				sqlE.printStackTrace();
			}//end catch
		
			
		}
		if(source == delB)
		{
			try
			{
				
			}
			catch(Exception excep)
			{
				excep.printStackTrace();
			}
		}
		if(source == returnB)
		{
			try
			{
				
			}
			catch(Exception excep)
			{
				excep.printStackTrace();
			}
		}
	}			
}


